--Api 表
/*
select * from SYS_Apis
select * from SYS_ApiM --M  Memo Main Manage

ReturnType
返回类型（类似返回值）
1 execSql 
2 openSql
3 execProc(不带返回结果) 
4 openProc(带返回结果集)
5 getList (使用getList sql 模板)
*/

declare 
  @ApiName varchar(50)='sjjd.moveToJD',
  @ReturnType int =6
--
--
delete from SYS_Apis where ApiName=@ApiName
delete from SYS_ApiM where apiName=@ApiName
insert into SYS_ApiM([apiName],[name],[memo])
select @ApiName,'阶段移动到阶段','阶段移动到某一阶段下'
insert into SYS_Apis(ApiName,paramsLen,params,ReturnType,sqlText)
select @ApiName,0,
null,
@ReturnType,
'with t(jdid) as (
 select jdid from [#(dbname)]..sjjd where JDID=#para(jdid)
 union all
 select jd.jdid from [#(dbname)]..sjjd as jd,t where jd.dgnd + jd.pjdmc = t.jdid
)
if exists(select 1 from t where jdid=#para(targetJdid))
begin
  select 0 as ok,''不能将该阶段移动到自己或子孙阶段下'' as msg
  return
end
update [#(dbname)]..sjjd set IsDeleted=1,editDate=getdate() where jdid=#para(jdid)
select 1 as ok,''#(jdid)'' as jdid
'
